<#assign base=request.contextPath />
<!DOCTYPE html>
<div class="row">
	<div class="col-md-12 col-sm-12 col-xs-12">
		<div class="x_panel">
			<div class="x_title">
				<h2>图片编辑 <small></small></h2>
				<div class="clearfix"></div>
			</div>
			<div class="x_content">
				<br/>
				<form id="postForm" data-parsley-validate class="form-horizontal form-label-left" method="post" action="${base}/gx/scrollPicture/save">
					<input type="hidden" id="id" name="id" value="${((obj.id)?c)!0 }">
		            <input type="hidden" name="addTime" value="${(obj.addTime)!.now?string['yyyy-MM-dd HH:mm:ss']}">
		            <input type="hidden" name="updateTime" value="${.now?string['yyyy-MM-dd HH:mm:ss']}">

					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">图片标题 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="name" name="name" value="${(obj.name)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
			
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">图片 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="file" id="icon_dropify" name="file" class="dropify" data-default-file="${imagePath}${(obj.path)!''}" />
                            <input type="hidden" name="path" id="path" value="${(obj.path)!''}">
                            <input type="hidden" name="pathOld" id="pathOld" value="${(obj.path)!''}">
                        </div>
					</div>
					
				
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">图片内容 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="subject" name="subject" value="${(obj.subject)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>


					<div class="ln_solid"></div>
					<div class="form-group">
						<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
							<button type="button" class="btn btn-success" id="submit">保存</button>
							<button type="button" class="btn btn-primary" id="goBack">返回</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>


<script type="text/javascript">
$(function() {
	//select2
	$(".select2").select2({width: "100%"});
	$('.summernote').summernote({
        height: 350, // set editor height
        minHeight: null, // set minimum height of editor
        maxHeight: null, // set maximum height of editor
        focus: false, // set focus to editable area after initializing summernote
        lang: 'zh-CN',
        shortcuts:false //禁止使用快捷键
    });
    
	 $('.dropify').dropify({
     	messages: {
		        'default': '点击或拖拽文件到这里',
		        'replace': '点击或拖拽文件到这里来替换文件',
		        'remove':  '移除文件',
		        'error':   '对不起，你上传的文件太大了',
		    }
     });
     

    // Used events
     drEvent = $('#icon_dropify').dropify();
     drEvent.on('dropify.afterClear', function(event, element) {
     	$("#scrollPicture").val("");
     });

     drEvent.on('dropify.errors', function(event, element) {
         console.log('Has Errors');
     });

	$("#goBack").click(function() {
		$("#main_content").load('${base}/gx/scrollPicture/list');	        
    });
  
    
	$("#submit").click(function() {
		var name = $.trim($("#name").val());
		var subject = $.trim($("#subject").val());
		var path = $.trim($("#path").val());
		
		//获取数据
		drEvent = $('.dropify').dropify();
		drEvent=drEvent.data('dropify')
		if((drEvent.file.object !=null )){
		var path = drEvent.callBackBase64;
		path = path.substring(path.indexOf("base64")+7);
		$("#path").val(path);
		}else{
			if($("#path").val()==""){
		    	swal("请上传图片");
		        return;
		    }
		}
	
		if(name==""){
    		swal("请输入图片标题");
            return;
    	} 
    	
    	if(subject==""){
    		swal("请输入图片内容");
            return;
    	}
		
        $("#postForm").ajaxSubmit(function(data) {
    	 	if (data.flag) {
    	 		swal(data.msg, "", "success");
				$("#main_content").load('${base}/gx/scrollPicture/list');
    	 	} 
    	 	else {
    	 		swal(data.msg, "", "error");
    	 	}
    	 	
    	});
	});
});
</script>